/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import java.io.Serializable;
import java.util.List;

/**
 *
 * @author Thai Ha Cong
 */

public class Product implements Serializable {
    private Integer idProduct;
    private String code;
    private String name;
    private String summary;
    private String details;
    private String brand;
    private String others;
    private double unitPrice;
    private int stockQuantity;
    private double sale;
    private String imageurl;
    private Category category;
    private List<Orderitem> orderitemList;
    private List<Receiptitem> receiptitemList;

    //details
    private String dimension;
    private String weight;
    private Integer warranty;
    private String color;
    private Double screenSize;
    private String display;
    private Integer storage;
    private Double camera;
    private String battery;
    private String os;
    private String data;
    private String processor;
    private String memory;
    private String graphics;
    private String hardDrive;
    private String packageContent;
    
    
    public Product() {
    }

    public Product(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public Product(Integer idProduct, String code, String name, String brand, double unitPrice) {
        this.idProduct = idProduct;
        this.code = code;
        this.name = name;
        this.brand = brand;
        this.unitPrice = unitPrice;
    }

    
    public Product(Integer idProduct, String name, String summary, String details, String brand, String others, double unitPrice, int stockQuantity, double sale, String imageurl) {
        this.idProduct = idProduct;
        this.name = name;
        this.summary = summary;
        this.details = details;
        this.brand = brand;
        this.others = others;
        this.unitPrice = unitPrice;
        this.stockQuantity = stockQuantity;
        this.sale = sale;
        this.imageurl = imageurl;
    }

    public Product(Integer idProduct, String name, String summary, String details, String brand, String others, double unitPrice, int stockQuantity, double sale, String imageurl, Category category) {
        this.idProduct = idProduct;
        this.name = name;
        this.summary = summary;
        this.details = details;
        this.brand = brand;
        this.others = others;
        this.unitPrice = unitPrice;
        this.stockQuantity = stockQuantity;
        this.sale = sale;
        this.imageurl = imageurl;
        this.category = category;
    }

    public Product(Integer idProduct, String code, String name, String summary, String details, String brand, String others, double unitPrice, int stockQuantity, double sale, String imageurl, Category category) {
        this.idProduct = idProduct;
        this.code = code;
        this.name = name;
        this.summary = summary;
        this.details = details;
        this.brand = brand;
        this.others = others;
        this.unitPrice = unitPrice;
        this.stockQuantity = stockQuantity;
        this.sale = sale;
        this.imageurl = imageurl;
        this.category = category;
    }

    public Product(Integer idProduct, String code, String name, String summary, String details, String brand, String others, double unitPrice, int stockQuantity, double sale, String imageurl) {
        this.idProduct = idProduct;
        this.code = code;
        this.name = name;
        this.summary = summary;
        this.details = details;
        this.brand = brand;
        this.others = others;
        this.unitPrice = unitPrice;
        this.stockQuantity = stockQuantity;
        this.sale = sale;
        this.imageurl = imageurl;
    }

    public Product(Integer idProduct, String code, String name, String summary, String details, String brand, String others, double unitPrice, int stockQuantity, String imageurl, Category category, String dimension, String weight, Integer warranty, String color, Double screenSize, String display, Integer storage, Double camera, String battery, String os, String data, String processor, String memory, String graphics, String hardDrive, String packageContent) {
        this.idProduct = idProduct;
        this.code = code;
        this.name = name;
        this.summary = summary;
        this.details = details;
        this.brand = brand;
        this.others = others;
        this.unitPrice = unitPrice;
        this.stockQuantity = stockQuantity;
        this.imageurl = imageurl;
        this.category = category;
        this.dimension = dimension;
        this.weight = weight;
        this.warranty = warranty;
        this.color = color;
        this.screenSize = screenSize;
        this.display = display;
        this.storage = storage;
        this.camera = camera;
        this.battery = battery;
        this.os = os;
        this.data = data;
        this.processor = processor;
        this.memory = memory;
        this.graphics = graphics;
        this.hardDrive = hardDrive;
        this.packageContent = packageContent;
    }

    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(Integer idProduct) {
        this.idProduct = idProduct;
    }

    public String getName() {
        return name;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "Product Name is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "Product name must contain more than 5 characters.", minLength = "5")})
    public void setName(String name) {
        this.name = name;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public String getBrand() {
        return brand;
    }

     @RequiredStringValidator(message = "Brand is required.")
    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getOthers() {
        return others;
    }

    public void setOthers(String others) {
        this.others = others;
    }

    @RequiredStringValidator(message = "Unit price is required.")
    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public int getStockQuantity() {
        return stockQuantity;
    }

     @RequiredStringValidator(message = "Stock quantity is required.")
    public void setStockQuantity(int stockQuantity) {
        this.stockQuantity = stockQuantity;
    }

    public double getSale() {
        return sale;
    }

    public void setSale(double sale) {
        this.sale = sale;
    }

    public String getImageurl() {
        return imageurl;
    }

    public void setImageurl(String imageurl) {
        this.imageurl = imageurl;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public List<Orderitem> getOrderitemList() {
        return orderitemList;
    }

    public void setOrderitemList(List<Orderitem> orderitemList) {
        this.orderitemList = orderitemList;
    }

    public List<Receiptitem> getReceiptitemList() {
        return receiptitemList;
    }

    public void setReceiptitemList(List<Receiptitem> receiptitemList) {
        this.receiptitemList = receiptitemList;
    }

    public String getDimension() {
        return dimension;
    }

    public void setDimension(String dimension) {
        this.dimension = dimension;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getDisplay() {
        return display;
    }

    public void setDisplay(String display) {
        this.display = display;
    }

    public String getBattery() {
        return battery;
    }

    public void setBattery(String battery) {
        this.battery = battery;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getProcessor() {
        return processor;
    }

    public void setProcessor(String processor) {
        this.processor = processor;
    }

    public String getMemory() {
        return memory;
    }

    public void setMemory(String memory) {
        this.memory = memory;
    }

    public String getGraphics() {
        return graphics;
    }

    public void setGraphics(String graphics) {
        this.graphics = graphics;
    }

    public String getHardDrive() {
        return hardDrive;
    }

    public void setHardDrive(String hardDrive) {
        this.hardDrive = hardDrive;
    }

    public String getPackageContent() {
        return packageContent;
    }

    public void setPackageContent(String packageContent) {
        this.packageContent = packageContent;
    }

    public Integer getWarranty() {
        return warranty;
    }

    public void setWarranty(Integer warranty) {
        this.warranty = warranty;
    }

    public Double getScreenSize() {
        return screenSize;
    }

    public void setScreenSize(Double screenSize) {
        this.screenSize = screenSize;
    }

    public Integer getStorage() {
        return storage;
    }

    public void setStorage(Integer storage) {
        this.storage = storage;
    }

    public Double getCamera() {
        return camera;
    }

    public void setCamera(Double camera) {
        this.camera = camera;
    }
    
    public void createSpecs() {
        if (dimension != null) {
            details = details + "\r\n" + "\r\n" + "Dimension: " + dimension;
        }
        if (weight != null) {
            details = details + "\r\n" + "Weight: " + weight;
        }
        if (warranty != null) {
            details = details + "\r\n" + "Warranty: " + warranty + " month(s)";
        }
        if (color != null) {
            details = details + "\r\n" + "\r\n" + "Color: " + color;
        }
        if (screenSize != null) {
            details = details + "\r\n" + "\r\n" + "Screen Size: " + screenSize + " inch(es)";
        }
        if (display != null) {
            details = details + "\r\n" + "Display: " + display;
        }
        if (storage != null) {
            details = details + "\r\n" + "Storage: " + storage + " GB";
        }
        if (camera != null) {
            details = details + "\r\n" + "Camera: " + camera + " MP";
        }
        if (battery != null) {
            details = details + "\r\n" + "\r\n" + "Battery: " + battery;
        }
        if (os != null) {
            details = details + "\r\n" + "OS: " + os;
        }
        if (data != null) {
            details = details + "\r\n" + "Data: " + data;
        }
        if (processor != null) {
            details = details + "\r\n" + "\r\n" + "Processor: " + processor;
        }
        if (memory != null) {
            details = details + "\r\n" + "Memory: " + memory;
        }
        if (graphics != null) {
            details = details + "\r\n" + "Graphics: " + graphics;
        }
        if (hardDrive != null) {
            details = details + "\r\n" + "Hard Drive: " + hardDrive;
        }
        if (packageContent != null) {
            details = details + "\r\n" + "\r\n" + "Package Content: " + packageContent;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProduct != null ? idProduct.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.idProduct == null && other.idProduct != null) || (this.idProduct != null && !this.idProduct.equals(other.idProduct))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Product[ idProduct=" + name + " ]";
    }
    
}
